<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // //1.创建XHR对象
        // let xhr = new XMLHttpRequest();
        // //2.调用open函数
        // xhr.open('POST', 'http://www.liulongbin.top:3006/api/addbook');
        // //设置Content-Type属性(固定写法)
        // xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        // //4.调用send函数
        // xhr.send('bookname=黑马传&author=老王&publisher=黑马出版社');
        // //4.监听onreadystatechange事件
        // xhr.onreadystatechange = function () {
        //     if (xhr.readyState == 4 && xhr.status == 200) {
        //         //获取服务器响应的数据
        //         console.log(xhr.responseText);
        //     }
        // }


        const xhr1 = new XMLHttpRequest();
        xhr1.open("POST", "http://www.liulongbin.top:3006/api/addbook");
        xhr1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr1.send('bookname=小西街啊&author=老舍&publisher=江西出版社');
        xhr1.onreadystatechange = function () {
            if (xhr1.readyState === 4 && xhr1.status === 200) {
                console.log(xhr1.responseText);
            }

        }
    </script>
</body>

</html>